package yealink;

/**
 * Created by lizhenyu on 2019/9/18
 * description
 */
import java.util.Scanner;

public class ExcelAddress {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String nStr = scanner.nextLine();
        for (int i = 0; i < Integer.valueOf(nStr); i++) {
            String input = scanner.nextLine();
            System.out.println(toNormalAddr(input));
        }
    }

    // transform to normal address
    private static String toNormalAddr(String input) {
        StringBuilder sb = new StringBuilder();
        char col_1, col_2;
        // 处理RC行列
        String str = input.replace('R', ' ').replace('C', ' ').trim();
        String[] strs = str.split(" ");
        if(strs.length == 2) {
            int row = Integer.parseInt(strs[0]);
            int col = Integer.parseInt(strs[1]);
            col_1 = (char) (col / 26 + 'A' - 1);
            col_2 = (char) (col % 26 + 'A' - 1);
            if(col > 26) {
                sb.append(col_1);
            }
            sb.append(col_2);
            sb.append(row);
            return sb.toString();
        }
        return null;
    }
}
